package com.alstudio.module.xmpp.protocol.xmpp.parser.iq.rank;

import com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener;
import com.alstudio.module.xmpp.protocol.xmpp.packact.ALIQ;
import com.alstudio.module.xmpp.protocol.xmpp.parser.iq.ALBaseIQParser;
import com.alstudio.module.xmpp.protocol.xmpp.parser.iq.IQParseEventHandler.IQXmlParseEventCallback;
import com.alstudio.utils.formater.numeric.ALNumericUtils;

public class CheckUserRankingRankParser extends ALBaseIQParser implements
		IQXmlParseEventCallback {

	private String popular;
	private String rich;
	private String glamour;

	private String popularValue;
	private String richValue;
	private String glamourValue;

	@Override
	public void parseIQPackage(ALIQ packact, String stream,
			ALXmppEventListener listener) throws Exception {
		// TODO Auto-generated method stub
		code = 0;
		popular = "";
		rich = "";
		glamour = "";

		popularValue = "";
		richValue = "";
		glamourValue = "";
		mListener = listener;
		startParse(packact, stream, this);
	}

	@Override
	public void processErrorStartTag(String tag) {
		// TODO Auto-generated method stub
		if (tag.equals(ERROR_CODE_TAG)) {
			code = ALNumericUtils.parseInt(getAttValue("code"), 0);
		}
	}

	@Override
	public void processSetStartTag(String tag) {
		// TODO Auto-generated method stub

	}

	@Override
	public void processGetStartTag(String tag) {
		// TODO Auto-generated method stub

	}

	@Override
	public void processResultStartTag(String tag) {
		// TODO Auto-generated method stub
		if (tag.equals("popular")) {
			popularValue = getAttValue("value");
			popular = readText();
		} else if (tag.equals("rich")) {
			richValue = getAttValue("value");
			rich = readText();
		} else if (tag.equals("glamour")) {
			glamourValue = getAttValue("value");
			glamour = readText();
		}
	}

	@Override
	public void processEndTag(String tag) {
		// TODO Auto-generated method stub

	}

	@Override
	public void processStartDocument() {
		// TODO Auto-generated method stub

	}

	@Override
	public void processEndDocument() {
		// TODO Auto-generated method stub
		onCallback();
	}

	@Override
	public void onCallback() {
		// TODO Auto-generated method stub
		if (mListener != null) {
			mListener.onGetRankingRankResult(code, popular, rich, glamour,
					popularValue, richValue, glamourValue);
		}
	}

}
